home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Programming / LEDA / source / src / graph_alg / _bfs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-16  |  1.1 KB  |  46 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  3.1c
  4. +
  5. +
  6. +  _bfs.c
  7. +
  8. +
  9. +  Copyright (c) 1994  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15.  
  16. /*******************************************************************************
  17. *                                                                              *
  18. *  BFS  (breadth first search)                                                 *
  19. *                                                                              *
  20. *******************************************************************************/
  21.  
  22.  
  23. #include <LEDA/graph_alg.h>
  24.  
  25. list<node> BFS(const graph&, node s, node_array<int>& dist)
  26.   list<node> Q(s);
  27.   node v,w;
  28.   list_item it;
  29.  
  30.   dist[s] = 0;
  31.   it = Q.first();
  32.  
  33.   while (it != nil)
  34.     { v = Q[it];
  35.       forall_adj_nodes(w,v)
  36.          if (dist[w] < 0) { Q.append(w); 
  37.                             dist[w] = dist[v]+1;
  38.                            }
  39.       it = Q.succ(it);
  40.      }
  41.   return Q;
  42. }
  43.  
  44.